package com.aiyige.page.my.order.dialog;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.order.model.ScreenEntity;
import com.aiyige.page.my.order.model.TimeSelectionEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/10/17.
 */

public class OrderTimeAdapter extends BaseQuickAdapter<TimeSelectionEntity, BaseViewHolder> {

    public OrderTimeAdapter() {
        super(new LinkedList<TimeSelectionEntity>());
    }

    @Override
    protected void convert(BaseViewHolder helper, TimeSelectionEntity item) {
        ((OrderHolder) helper).bindData(item);
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = new OrderHolder(getItemView(R.layout.item_order_classify, parent));
        return baseViewHolder;
    }

    public class OrderHolder extends BaseViewHolder {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.iv_selection)
        ImageView ivSelection;

        TimeSelectionEntity entnty;

        public OrderHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }


        public void bindData(TimeSelectionEntity data) {
            entnty = data;
            tvName.setText(getTime(entnty.getTime()));
            ivSelection.setImageResource(entnty.isSelected()?R.drawable.order_screen_selected:R.drawable.order_screen_normal);
        }

    }

    /**
     * threeday-三天内, oneweek-一周内，twoweek-两周内， onemonth-一个月内，twomonth-两个月内
     * @return
     */
    private String getTime(String time) {
        if (TextUtils.isEmpty(time)) {
            return "";
        }
        if (time.equals(ScreenEntity.THREE_DAY)) {
            return "三天内";
        }
        if (time.equals(ScreenEntity.ONE_WEEK)) {
            return "一周内";
        }
        if (time.equals(ScreenEntity.TWO_WEEK)) {
            return "两周内";
        }
        if (time.equals(ScreenEntity.ONE_MONTH)) {
            return "一月内";
        }
        if (time.equals(ScreenEntity.TWO_MONTH)) {
            return "两月内";
        }
        if (time.equals(ScreenEntity.THREE_DAY)) {
            return "三天内";
        }
        return "";
    }

    public void reset() {
        List<TimeSelectionEntity> list =  getData();
        if (list == null || list.isEmpty()) {
            return;
        }
        for (TimeSelectionEntity entity : list) {
            entity.setSelected(false);
        }
        notifyDataSetChanged();
    }

}
